let obj = {
    name:'zyx',
    age:18,
    like:{
        n:'骑车'
    }
}


function deepClone(obj){
    let clone = obj instanceof Array?[]:{}//不能使用Object，因为array也是object
    for(let key in obj){
        if(obj.hasOwnProperty(key) ){
            //key 是不是obj显示拥有的属性
            // clone[key] = obj[key]
            // if(typeof obj[key] == 'object' &&  obj[key]!==null){
            //     clone[key]=deepClone(obj[key])
            // }
            // else{
            //     clone[key]=obj[key]
            // }
            if(obj[key] instanceof Object){
                clone[key] = deepClone(obj[key])
            }else{
                clone[key]=obj[key]
            }
        }
    }

    return clone
}

let newObj = deepClone(obj)
obj.like.n = '打球'

console.log(newObj);
